package com.material.web.controller.supplier;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.material.common.utils.SecurityUtils;
import com.material.supplier.params.SupplierReservationQuery;
import com.material.supplier.vo.SupplierReservationDataVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.material.common.annotation.Log;
import com.material.common.core.controller.BaseController;
import com.material.common.core.domain.AjaxResult;
import com.material.common.enums.BusinessType;
import com.material.supplier.domain.SupplierReservation;
import com.material.supplier.service.ISupplierReservationService;
import com.material.common.utils.poi.ExcelUtil;
import com.material.common.core.page.TableDataInfo;

/**
 * 供应商预约送料Controller
 * 
 * @author ruoyi
 * @date 2025-05-07
 */
@RestController
@RequestMapping("/supplier/reservation")
public class SupplierReservationController extends BaseController
{
    @Autowired
    private ISupplierReservationService supplierReservationService;

    /**
     * 查询供应商预约送料列表
     */
    @PreAuthorize("@ss.hasPermi('supplier:reservation:list')")
    @GetMapping("/list")
    public TableDataInfo list(SupplierReservationQuery supplierReservation)
    {
        Long bizId = getBizId();
        boolean admin = SecurityUtils.isAdmin(getUserId());
        if(!admin){
            supplierReservation.setFactoryId(bizId);
        }
        startPage();
        List<SupplierReservationDataVo> list = supplierReservationService.selectSupplierReservationPageList(supplierReservation);
        return getDataTable(list);
    }

    /**
     * 导出供应商预约送料列表
     */
    @PreAuthorize("@ss.hasPermi('supplier:reservation:export')")
    @Log(title = "供应商预约送料", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SupplierReservation supplierReservation)
    {
        List<SupplierReservation> list = supplierReservationService.selectSupplierReservationList(supplierReservation);
        ExcelUtil<SupplierReservation> util = new ExcelUtil<SupplierReservation>(SupplierReservation.class);
        util.exportExcel(response, list, "供应商预约送料数据");
    }

    /**
     * 获取供应商预约送料详细信息
     */
    @PreAuthorize("@ss.hasPermi('supplier:reservation:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(supplierReservationService.selectSupplierReservationById(id));
    }

    /**
     * 新增供应商预约送料
     */
    @PreAuthorize("@ss.hasPermi('supplier:reservation:add')")
    @Log(title = "供应商预约送料", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SupplierReservation supplierReservation)
    {
        return toAjax(supplierReservationService.insertSupplierReservation(supplierReservation));
    }

    /**
     * 修改供应商预约送料
     */
    @PreAuthorize("@ss.hasPermi('supplier:reservation:edit')")
    @Log(title = "供应商预约送料", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SupplierReservation supplierReservation)
    {
        return toAjax(supplierReservationService.updateSupplierReservation(supplierReservation));
    }

    /**
     * 修改供应商预约送料
     */
    @PreAuthorize("@ss.hasPermi('supplier:reservation:sign')")
    @Log(title = "供应商预约送料", businessType = BusinessType.UPDATE)
    @PutMapping("/sign")
    public AjaxResult sign(@RequestBody SupplierReservation supplierReservation)
    {
        supplierReservationService.signUp(supplierReservation.getId());
        return AjaxResult.success();
    }

    /**
     * 删除供应商预约送料
     */
    @PreAuthorize("@ss.hasPermi('supplier:reservation:remove')")
    @Log(title = "供应商预约送料", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(supplierReservationService.deleteSupplierReservationByIds(ids));
    }
}
